/**
 * 
 */
package oauth.service.finger;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oauth.repository.mapperadd.SpringSecurityMapper;
import oauth.repository.modelAdd.SysFingerDTO;

/**
 * @author Pan JinWen
 * @time 2016年6月15日上午9:38:43
 */
@Service
@WebService
public class FingerMatch {
	@Autowired
	private FingerDll fingerDll;
	@Autowired
	private SpringSecurityMapper springSecurityMapper;
	private static int status = 0;
	private static float[] score = new float[1];
	private static Map<String, Object> map = new HashMap<String, Object>();

	public @WebResult(name = "status") Map<String, Object> match(@WebParam(name = "fingercode") String fingercode) {
		List<SysFingerDTO> selectAllFinger = springSecurityMapper.selectAllFingerCode();
		fingerDll.fingerBegin();
		System.err.println(fingercode);
		for (SysFingerDTO i : selectAllFinger) {
			try {
				status = fingerDll.fingermatch(fingercode, i.getFinger_code(), score);
			} catch (IOException e) {
				map.clear();
				map.put("error", "输入的指纹特征码错误！");
				return map;
			}
			// if (fingerDll.fingermatch(fingercode, i.getFinger_code(), (byte)
			// 3, score) == 1)
			System.err.println("状态：" + status + "    匹配值: " + score[0]);
			if (status == 1 && score[0] >= 0.5) {
				map.clear();
				map.put("score", score[0]);
				map.put("username", i.getUser_name());
				map.put("finger_id", i.getFinger_id());
				System.err.println("@@@！匹配成功！@@@    用户名:" + map.get("username") + "    指位：" + map.get("finger_id"));
				return map;
			} else if (status < 0) {
				map.clear();
				map.put("status_id", status);
				map.put("error", "服务器内部错误！");
				return map;
			}
		}
		map.clear();
		map.put("error", "无匹配指纹，或是指纹质量不佳！");
		return map;
	}
}
